/***************************************************************************

 This source file is part of OGREBULLET
 (Object-oriented Graphics Rendering Engine Bullet Wrapper)
 For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10

 Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes)



 This source file is not LGPL, it's public source code that you can reuse.
 -----------------------------------------------------------------------------*/
#ifndef _OGREBULLET_Primitives_Demo__H
#define _OGREBULLET_Primitives_Demo__H

#include "OgreBulletDynamics.h"
#include "OgreBulletListener.h"
#include <vector>
#include "OgreBulletDynamicsRigidBody.h"
#include "Cell.h"
#include "StemLifeScene.h"
#include <list>
#include <BioEntity.h>
#include <map>

using namespace Ogre;
using OgreBulletDynamics::RigidBody;
// -------------------------------------------------------------------------
class StemLifeScene: public OgreBulletListener {
public:

	StemLifeScene() :
		OgreBulletListener() {
		mName = "Primitives Test Scene";
	};
	virtual ~StemLifeScene() {

	};

	void init(Ogre::Root *root, Ogre::RenderWindow *win,
			OgreBulletApplication *application);

	void initWorld(
			const Ogre::Vector3 &gravityVector = Ogre::Vector3(0, -9.81, 0),
			const Ogre::AxisAlignedBox &bounds = Ogre::AxisAlignedBox(
					Ogre::Vector3(-10000, -10000, -10000),
					Ogre::Vector3(10000, 10000, 10000)));

	virtual OgreBulletDynamics::RigidBody* addFood(
			const Ogre::String instanceName, const Ogre::Vector3 &pos,
			const Ogre::Quaternion &q, const Ogre::Real &radius,
			const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction,
			const Ogre::Real bodyMass);

	virtual Cell* addCell(
			const Ogre::String instanceName, const Ogre::Vector3 &pos,
			const Ogre::Quaternion &q, const Ogre::Real radius,
			const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction,
			const Ogre::Real bodyMass);

	void remove(BioEntity* be);
	void keyPressed(BULLET_KEY_CODE key);

	virtual bool frameStarted(Real elapsedTime);

	void processBioCollisions();
protected:
	struct kdtree* kdFood;
	std::set<BioEntity*> bioEntities;
	std::map<RigidBody*,int> bodyIndex;
};

#endif //_OGREBULLET_Primitives_Demo__H
